package com.dataseek.iot.device.manager.handler;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dataseek.iot.core.handler.ServiceHandler;
import com.dataseek.iot.core.response.ResponseEntity;
import com.dataseek.iot.mysql.entity.MqttAccount;
import com.dataseek.iot.mysql.service.impl.MqttAccountServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.util.List;

/**
 * @author cc
 * @Title: 设备账号handler
 * @Description: 设备账号handler
 * @date 2021/11/1311:03 上午
 * @since 1.0
 */
@Service
@Slf4j
public class MqttAccountHandler extends ServiceHandler<MqttAccount> {

    @Autowired
    MqttAccountServiceImpl deviceAccountService;


    @Override
    public Mono<ResponseEntity> saveOne(Object entity) {
        Boolean isSaved =  deviceAccountService.save((MqttAccount) entity);
        return this.createResponse(isSaved);
    }

    @Override
    public Mono<ResponseEntity> saveBatch(List lists) {
        Boolean isSaved =  deviceAccountService.saveBatch(lists);
        return this.createResponse(isSaved);
    }


    @Override
    public Mono<ResponseEntity> removeById(String id) {
        Boolean isRemoved =  deviceAccountService.removeById(id);
        return this.createResponse(isRemoved);
    }

    @Override
    public Mono<ResponseEntity> removeAll(List ids) {
        Boolean isRemoved = deviceAccountService.removeByIds(ids);
        return this.createResponse(isRemoved);
    }

    @Override
    public Mono<ResponseEntity> remove(Wrapper wrapper) {
        Boolean isRemoved = deviceAccountService.remove(wrapper);
        return this.createResponse(isRemoved);
    }

    @Override
    public Mono<ResponseEntity> remove(String id) {
        Boolean isRemoved = deviceAccountService.removeById(id);
        return this.createResponse(isRemoved);
    }

    @Override
    public Mono<ResponseEntity> updateOne(Object entity) {
        Boolean isUpdated = deviceAccountService.updateById((MqttAccount) entity);
        return this.createResponse(isUpdated);
    }

    @Override
    public Mono<ResponseEntity> update(Wrapper wrapper) {
        Boolean isUpdated = deviceAccountService.update(wrapper);
        return this.createResponse(isUpdated);
    }

    @Override
    public Mono<ResponseEntity> updateBatch(List entities) {
        Boolean isUpdated = deviceAccountService.updateBatchById(entities);
        return this.createResponse(isUpdated);
    }

    @Override
    public Mono<ResponseEntity> findOne(String id) {
        MqttAccount p = deviceAccountService.getById(id);
        return this.createResponse(p);
    }

    @Override
    public Mono<ResponseEntity> page(Page p) {
        Page page = deviceAccountService.page(p);
        return this.createResponse(page);
    }

    @Override
    public Mono<ResponseEntity> page(Page p, Wrapper wrapper) {
        Page page = deviceAccountService.page(p, wrapper);
        return this.createResponse(page);
    }

    @Override
    public Flux<ResponseEntity> find(List ids) {
        List<MqttAccount> products = deviceAccountService.listByIds(ids);
        return this.createResponse(products);
    }

    @Override
    public Flux<ResponseEntity> find(Wrapper wrapper) {
        List list = deviceAccountService.list(wrapper);
        return this.createResponse(list);
    }

    @Override
    public Flux<ResponseEntity> findAll() {
        List list = deviceAccountService.list();
        return this.createResponse(list);
    }

    @Override
    public Mono<ResponseEntity> defaultResponseOne(ResponseEntity responseEntity) {
        return Mono.just(responseEntity);
    }

    @Override
    public Flux<ResponseEntity> defaultResponseTwo(ResponseEntity responseEntity) {
        return Flux.just(responseEntity);
    }
}
